/**
 * 
 */
package com.mie.producer;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author Mie
 *
 */
public class Producer_PubSub {
	public static void main(String[] args) throws IOException, TimeoutException {
		//1.create factory
		ConnectionFactory factory=new ConnectionFactory();
		//2.set parameter
		factory.setHost("localhost");//defaults localhost
		factory.setPort(5672);
		factory.setVirtualHost("/");
		factory.setUsername("rollen");
		factory.setPassword("root");
		//3.create connection
		Connection connection=factory.newConnection();
		//4.create channel 
		Channel channel=connection.createChannel();
		//5.create exchange
		String exchangeName="test_fanout";
		channel.exchangeDeclare(exchangeName, BuiltinExchangeType.FANOUT, true, false, false, null);
		//6.declare queue
		String queue1Name="test_fanout_queue1";
		String queue2Name="test_fanout_queue2";
		channel.queueDeclare(queue1Name, true, false, false, null);
		channel.queueDeclare(queue2Name, true, false, false, null);
		//7.bind queue and exchange
		channel.queueBind(queue1Name, exchangeName, "");
		channel.queueBind(queue2Name, exchangeName, "");
		//8.send message
		String body="log: zhangsan recall findAll method";
		channel.basicPublish(exchangeName, "", null, body.getBytes());
		channel.close();
		connection.close();
		
		
	}

}
